package cn.bytecollege.dao;

import cn.bytecollege.entity.Vip;
import java.util.List;

public class VipDao extends BaseDao<Vip,Integer>{
    /**
     * 根据id删除vip
     * zxy
     */
    public int delete(int vipId){
        String sql="DELETE FROM VIP WHERE VIP_ID=?";
        return helper.executeUpdate(sql,vipId);
    }

    /**
     * @author LH
     * 通过身份证号查询vip信息
     * @param idNumber
     * @return
     */
    public Vip findByIdNumber(String idNumber){
        String sql ="SELECT * FROM `vip` where vip_id_number=?";
        List<Vip> list= helper.executeQuery(sql,Vip.class,idNumber);
        Vip vip=null;
        if (list.size()>0){
            vip=list.get(0);
        }
        return vip;
    }
    /**
     * 分页查询Vip用户信息
     * @author Mr.East
     * @param pageIndex
     * @param pageSize
     * @param objects
     * @return
     */
    @Override
    public List<Vip> findByPage(int pageIndex, int pageSize, Object... objects) {
        String sql = "SELECT vip_Id,vip_Name,vip_Gender,vip_Id_Number," +
                "vip_Phone_Number,vip_Create_Time FROM VIP LIMIT ?,?";
        Object[] obj = {(pageIndex-1)*pageSize,pageSize};
        return helper.executeQuery(sql,Vip.class,obj);
    }

    /**
     * 查询所有的用户数
     * @author MrEast
     * *
     */
    public int count(){
        String sql = "SELECT COUNT(*) FROM VIP";
        return helper.executeScale(sql);
    }

    /**
     * 新增会员信息
     * @author Mr.East
     * @param vip
     * @return
     */
    @Override
    public int save(Vip vip) {
        String sql = "INSERT INTO VIP( VIP_NAME,VIP_GENDER,VIP_ID_NUMBER," +
                "VIP_PHONE_NUMBER,VIP_CREATE_TIME ) VALUES(?,?,?,?,?)";
        Object[] objects = {vip.getVipName(),vip.getVipGender(), vip.getVipIdNumber(),
                vip.getVipPhoneNumber(),vip.getVipCreateTime()};
        return helper.executeUpdate(sql,objects);
    }

    /**
     * 修改（更新）会员信息
     * @author Mr.East
     * @param vip
     * @return
     */
    @Override
    public int update(Vip vip) {
        String sql = "UPDATE VIP SET VIP_NAME = ?,VIP_GENDER = ?,VIP_ID_NUMBER = ?," +
                "VIP_PHONE_NUMBER = ? WHERE VIP_ID = ? " ;
        Object[] objects = {vip.getVipName(),vip.getVipGender(),
                vip.getVipIdNumber(),vip.getVipPhoneNumber(),vip.getVipId()};
        return helper.executeUpdate(sql,objects);
    }

    /**
     * 执行修改中的查询
     * @author Mr.East
     * @param vipId
     * @return
     */
    public List<Vip> findByVipId(Integer vipId) {
        String sql ="SELECT vip_id,vip_Name,vip_Gender,vip_Id_Number," +
                "vip_Phone_Number FROM VIP WHERE VIP_ID =  ?";
        return helper.executeQuery(sql,Vip.class,vipId);
    }


}
